<template>
    投资项目名称:<input type="text" v-model="sname">
    <input type="button" value="查询" @click="show(0)">
    <input type="button" value="正序" @click="paixu(1)">
    <input type="button" value="倒序" @click="paixu(2)">
    <table class="table table-border" border="1" cellspacing="0" cellpadding="0" >
        <thead>
            <tr>
                <td>投资项目编号</td>
                <td>投资项目名称</td>
                <td>投资项目总额度</td>
                <td>已投资额度</td>
                <td>剩余投资额度</td>
                <td>投资次数</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="iten in info">
                <td>{{ iten.IId }}</td>
                <td>{{ iten.IName }}</td>
                <td>{{ iten.IMoney }}</td>
                <td>{{ iten.StateMoney }}</td>
                <td>{{ iten.EndMoney }}</td>
                <td>{{ iten.ISum }}</td>
                <td><slot :id="iten.IId"></slot></td>
            </tr>
        </tbody>
    </table>
    <div>
        一共有{{ pageinfos.recourdcount }}条数据,每页{{ pageinfos.pagesize }}条,当前第{{ pageinfos.pageindex }}页,当前第{{ pageinfos.pageindex }}/{{ pageinfos.pagecount }}页
        <a href="#" @click="page('A')">首页</a>
        <a href="#" @click="page('B')">上一页</a>
        <a href="#" @click="page('C')">下一页</a>
        <a href="#" @click="page('D')">尾页</a>
        <input type="text" v-model="index">
        <input type="button" value="GO" @click="search">
    </div>
</template>
<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios'
const info=ref([{
    IId:0,
    IName:"",
    IMoney:0,
    StateMoney:0,
    EndMoney:0,
    ISum:0
}])
const sname=ref("")
const pageinfos=ref({
    pagesize:2,
    pageindex:1,
    pagecount:0,
    recourdcount:0
})
onMounted(()=>{
    show(0)
})
const show=(ssid:number)=>{
axios({
    url:"https://localhost:44394/api/InverstController/InverstShow",
    method:"get",
    params:{
        name:sname.value,
        ssid:ssid,
        pagesize:pageinfos.value.pagesize,
        pageindex:pageinfos.value.pageindex
    }
})
.then(res=>{
    console.log(res.data)
    info.value=res.data.list
    pageinfos.value.pagecount=res.data.pagecount
    pageinfos.value.recourdcount=res.data.recourdcount
    
})
}

const paixu=(a:number)=>{
show(a)
}

const page=(masg:string)=>{
switch(masg){
    case "A":
        pageinfos.value.pageindex=1
        break;
    case "B":
        if(pageinfos.value.pageindex>1){
            pageinfos.value.pageindex--
        }else{
            alert('已经是第一页了')
        }
        break;
    case "C":
        if(pageinfos.value.pageindex<pageinfos.value.pagecount){
            pageinfos.value.pageindex++
        }else{
            alert('已经是最后一页了')
        }
        break;
    case "D":
        pageinfos.value.pageindex=pageinfos.value.pagecount
        break;
}
show(0)
}
const index=ref("")
const search=()=>{
  
   if(index.value==""){
    alert('跳转页不能为空')
    return
   }
   if(Number(index.value)>pageinfos.value.pagecount){
    alert('跳转页不能大于总页数')
    return
   }
   if(isNaN(Number(index.value))){
    alert('跳转页纸能为数字')
    return
   }
   if(Number(index.value)<1){
    alert('跳转页不能小于1')
    return
   }
   pageinfos.value.pageindex=Number(index.value)
   show(0)
}
</script>
